package org.ezplatform.office.forum.web.rest;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.ezplatform.cloud.api.component.attachment.AttachmentUtilsService;
import org.ezplatform.cloud.api.component.popuser.PopUserScopeUtilService;
import org.ezplatform.cloud.api.system.user.UserApiService;
import org.ezplatform.cloud.common.client.RestClient;
import org.ezplatform.cloud.common.controller.BaseController;
import org.ezplatform.cloud.common.log.LogService;
import org.ezplatform.core.annotation.MenuData;
import org.ezplatform.core.common.WebUser;
import org.ezplatform.core.pagination.PropertyFilter;
import org.ezplatform.core.security.SecurityUtils;
import org.ezplatform.core.web.util.WebUtils;
import org.ezplatform.core.web.view.OperationResult;
import org.ezplatform.office.forum.entity.ForumBoard;
import org.ezplatform.office.forum.entity.ForumIntegral;
import org.ezplatform.office.forum.entity.ForumPost;
import org.ezplatform.office.forum.service.ForumBoardService;
import org.ezplatform.office.forum.service.ForumIntegralService;
import org.ezplatform.office.forum.service.ForumLabelService;
import org.ezplatform.office.forum.service.ForumPostLabelService;
import org.ezplatform.office.forum.service.ForumPostService;
import org.ezplatform.office.forum.util.forumpostsend.ForumPostSendUtils;
import org.ezplatform.util.DateUtils;
import org.ezplatform.util.GlobalConstant;
import org.ezplatform.util.JsonUtils;
import org.ezplatform.util.StringUtils;
import org.ezplatform.util.ValidateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 移动端控制类
 * 2019年11月2日17:40:59
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/api/m/forum")
public class ForumMobileApiController extends BaseController{
	
    private static final Logger LOG = LoggerFactory.getLogger(ForumMobileApiController.class);
	
    @Autowired
    private ForumBoardService forumBoardService;
    
    @Autowired
    private ForumPostLabelService forumPostLabelService;

    @Autowired
    private ForumPostService forumPostService;

    @Autowired
    private AttachmentUtilsService attachmentUtilsService;
    
    @Autowired
	private LogService logService;

    @Autowired
    private PopUserScopeUtilService popUserScopeUtilService;

    @Autowired
    private UserApiService userApiService;
    
    @Autowired
    private ForumLabelService forumLabelService;
    
    @Autowired
    private ForumIntegralService forumIntegralService;
    
    @Autowired
    private RestClient restClient;

    private Map buildResult(boolean success, Object content, String message) {
        Map r = new HashMap();
        r.put("success", success);
        r.put("content", content);
        if (org.ezplatform.util.StringUtils.isEmpty(message)) {
            r.put("message", success ? "获取数据成功" : "获取数据失败");
        } else {
            r.put("message", message);
        }
        return r;
    }

    private Map buildPageResult(boolean success, Page page, Integer currentPage) {
        Map content = new HashMap();
        content.put("data", page.getContent());
        content.put("currentPage", currentPage);
        return buildResult(true, content, null);
    }

    private Map buildOperationResult(OperationResult result) {
        Map r = new HashMap();
        if (org.ezplatform.util.StringUtils.equals(result.getType(), OperationResult.OPERATION_RESULT_TYPE.success.name()) ||
                org.ezplatform.util.StringUtils.equals(result.getType(), OperationResult.OPERATION_RESULT_TYPE.warning.name())) {
            r.put("success", true);
            r.put("content", result.getData());
            r.put("message", result.getMessage());
        } else if (org.ezplatform.util.StringUtils.equals(result.getType(), OperationResult.OPERATION_RESULT_TYPE.failure.name()) ||
                org.ezplatform.util.StringUtils.equals(result.getType(), OperationResult.OPERATION_RESULT_TYPE.unauthorized.name())) {
            r.put("success", false);
            r.put("errorMsg", result.getMessage());
            r.put("errorCode", result.getCode());
        }
        return r;
    }

    /**
     *
     * @param request
     * @return
     */
    @ApiOperation(value="获取论坛版块下拉树", notes="获取论坛版块下拉树")
    @RequestMapping(value="/getBoardTree", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map getBoardTreeWithDing(HttpServletRequest request){
        WebUser user = WebUtils.getCurrentUser();
        List<Map> resutl = forumBoardService.getTypeBoardTreeWithDDApp("", user.getCorpId(),user.getUserId());
        return buildResult(true, resutl, "获取论坛版块下拉树");
    }
	    
	    
    @ApiOperation(value="获取当前用户标记的标签", notes="获取所有标签")
    @RequestMapping(value="/postAllLabel", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map postAllLabel(HttpServletRequest request){
        WebUser user = WebUtils.getCurrentUser();
        String id=request.getParameter("id");
        List<Map> resutl = forumLabelService.getAllLabelById(id, user.getCorpId());
        return buildResult(true, resutl, "获取所有标签");
    }

    @ApiOperation(value="获取所有版块", notes="获取所有版块")
    @ApiImplicitParams({})
    @RequestMapping(value="/postAllBoard", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map postAllBoard(HttpServletRequest request) {
    	String boardId=request.getParameter("boardId");
    	List<Map> result = forumBoardService.getAllBoard(boardId);
    	return buildResult(true, result, "获取所有版块");
    }
	    
	    
	    
    /**
     * 当前用户可以发帖的版块
     * @param request
     * @return
     */
    @SuppressWarnings({ "unchecked", "rawtypes", "rawtypes" })
	@ApiOperation(value="当前用户可以发帖的版块", notes="获取论坛版块下拉树")
    @ApiImplicitParams({

    })
    @RequestMapping(value="/postBoards", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map postBoards(HttpServletRequest request){
        try {
            WebUser user = WebUtils.getCurrentUser();
            List<Map> list = forumBoardService.postBoardWithDingding(user.getUserId());
            //判断是否有管理员权限
      		boolean flag = false;
      		if(user.getRoleCodes().contains(ForumPost.CheckStatusEnum.YYGLYQX.getValue())||SecurityUtils.isSuperAdmin(user)) {
      			flag = true;
      		}
      		Map map = new HashMap();
      		map.put("isAdminRole", flag);
      		map.put("content", list);
            return buildResult(true, map, "当前用户可以发帖的版块成功");
        } catch (Exception e){
            LOG.error("当前用户可以发帖的版块失败", e);
            return buildResult(false, new ArrayList<Object>(), "当前用户可以发帖的版块失败");
        }
    }
	    
    @SuppressWarnings({ "unchecked", "rawtypes", "rawtypes" })
	@ApiOperation(value="当前用户可以发帖的版块", notes="获取论坛版块下拉树")
    @RequestMapping(value="/ifPost", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map ifPost(HttpServletRequest request){
    	//判断是否管理员或者版主,可以发公告贴,普通用户只有主题帖权限
    	boolean ifAdminOrModerator = true;
    	/*进行黑名单 过滤 不允许发帖*/
    	//获取当前用户
    	Map<String, Object> data = new HashMap();
        WebUser user = WebUtils.getCurrentUser();
        //获取公司id
        String corpId = user.getCorpId();
        String token = user.getJwtToken();
        if(!user.getRoleCodes().contains("appAdminRole")) {
        	//获取版块id
            String boardId = request.getParameter("boardId");
            //查找当前版主集合
            String moderatorScopeValue = popUserScopeUtilService.getScopeTypeValue("oa_forum_moderator_scope","oa_forum_board", "id",StringUtils.null2String(boardId));
            String moderatorScopeMap = userApiService.getScopeName(moderatorScopeValue,corpId,token);
            List<String> moderatorList = Arrays.asList(moderatorScopeMap.split(","));
            //如果当前用户不是版主,需要继续判断
            if(!moderatorList.contains(user.getCnName())) {
            	ifAdminOrModerator = false;
            	//查找当前版块黑名单集合
                String blackListScopeValue = popUserScopeUtilService.getScopeTypeValue("oa_forum_board_user_scope","oa_forum_board", "id",StringUtils.null2String(boardId));
                String blackListScopeMap = userApiService.getScopeName(blackListScopeValue,corpId,token);
                //如果黑名单是空的,默认所有人发帖
                if(blackListScopeMap==null || "".equals(blackListScopeMap)) {
                	data.put("ifPost", "true");
                	data.put("ifAdminOrModerator", false);
                	return buildResult(true, data, "获取是否可以发帖成功");
                }
                List<String> blackList = Arrays.asList(blackListScopeMap.split(","));
                String name = user.getCnName();
                if(blackList.contains(name)) {
                	data.put("ifAdminOrModerator", false);
                	data.put("ifPost","false");
                	return buildResult(true, data, "获取是否可以发帖成功");
                }
            }
        } 
        data.put("ifPost", "true");
        data.put("ifAdminOrModerator", ifAdminOrModerator);
        List<Map> list = new ArrayList();
        list.add(data);
        return buildResult(true, data, "获取是否可以发帖成功");
    }

    /**
     *
     * @param request
     * @return
     */
    @ApiOperation(value="获取论坛帖子列表", notes="根据数量范围+版块来获取帖子列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpId", value = "用户ID", required = true, paramType = "path", dataType = "String"),
            @ApiImplicitParam(name = "showNumber", value = "列表显示条数", required = true, paramType = "path", dataType = "String"),
            @ApiImplicitParam(name = "boardIds", value = "版块Ids", required = true, paramType = "path", dataType = "String"),
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "path", dataType = "String")
    })
    @RequestMapping(value="/getBoardPostList", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map getBoardPostListWithDing(HttpServletRequest request){
        WebUser user = WebUtils.getCurrentUser();
        String corpId = user.getCorpId();
        String showNumber = request.getParameter("showNumber");
        String boards = request.getParameter("boardIds");
        List<String> boardList = new ArrayList<String>();
        if(StringUtils.isNotBlank(boards)){
            boardList = Arrays.asList(boards.split(","));
        }
        List<Map> resutl = forumPostService.getBoardPostList(user.getJwtToken(), boardList, corpId, showNumber);
        return buildResult(true, resutl, "获取论坛帖子列表成功");
    }


    /**
     * 所有帖子列表
     * @param request
     * @return
     */
    @ApiOperation(value="所有帖子列表", notes="所有帖子列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "boardId", value = "版块Id", required = true, paramType = "path", dataType = "String")
    })
    @RequestMapping(value="/allpostList", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map findAllPostByPage(HttpServletRequest request){
        WebUser user = WebUtils.getCurrentUser();
        String corpId = user.getCorpId();
        String boardId = request.getParameter("boardId");
        String title = request.getParameter("title").trim();
        String type = request.getParameter("type");//1、以公告置顶排序，0相反
        String startDate = StringUtils.null2String(request.getParameter("startDate"));
        String endDate = StringUtils.null2String(request.getParameter("endDate"));
        //0 最新   1  最火
        String activeTabIndex = request.getParameter("activeTabIndex");
        String pageNum = request.getParameter("pageNum");
        String page = request.getParameter("page");
    	String pageSize = request.getParameter("pageSize");
    	List<Map> map1 = new ArrayList<Map>();
		List<Map> map2 = new ArrayList<Map>();
        List<Map> list = forumPostService.allPostListDing(page, pageSize, user.getJwtToken(), corpId, boardId, activeTabIndex,"dingding",title,type,startDate,endDate);
        Map content = new HashMap();
        if("1".equals(type)) {
        	for (Map map : list) {
    			boolean flag = false;
    			List<Map<String, Object>> scopeName = (List<Map<String, Object>>) map.get("labels");
    			for (Map<String, Object> mapValue : scopeName) {
    				if("公告".equals(mapValue.get("name").toString()) && "true".equals(mapValue.get("checked").toString())) {
    					map.put("flag", true);
    					map1.add(map);
    					flag = true;
    				}
    			}
    			if(!flag) {
    				map.put("flag", false);
    				map2.add(map);
    			}
    		}
            map1.addAll(map2);
            content.put("data", map1);
        }else {
        	content.put("data", list);
        }
        content.put("currentPage", Integer.valueOf(page));
        if(StringUtils.null2String(boardId).isEmpty()) {
        	logService.saveModuleLog("forum:navigation:02,查看", title, ""); 
        }
        return buildResult(true, content, null);
    }

    /**
     *
     * @Title: myPostList
     * @Description:
     *     我的帖子列表
     * @param request
     * @return
     * @return: Page<Map>
     *
     * @date 2017年11月22日 上午11:45:26
     *
     */
    @ApiOperation(value="我的帖子列表", notes="我的帖子列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型(1-主题帖; 2-回帖)", required = true, paramType = "path", dataType = "String")
    })
    @RequestMapping(value="/mypostList", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map myPostList(HttpServletRequest request){
        String corpId = WebUtils.getCurrentUser().getCorpId();
        String title = request.getParameter("title").trim();
        String type = request.getParameter("type");
        String page = request.getParameter("page");
    	String pageSize = request.getParameter("pageSize");
    	String checkStatus = request.getParameter("checkStatus");
        List<Map> list = forumPostService.myPostListDing(page, pageSize, TOKEN, corpId, type, title,checkStatus);
        Map content = new HashMap();
        content.put("data", list);
        content.put("currentPage", Integer.valueOf(page));
        return buildResult(true, content, null);
    }


    /**
     * 获取待审核列表
     * @param request
     * @return
     */
    @ApiOperation(value="获取待审核列表", notes="获取待审核列表")
    @ApiImplicitParams({
    })
    @RequestMapping(value="/unCheckPostList", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map unCheckPostList(HttpServletRequest request){
        WebUser user = WebUtils.getCurrentUser();
        String corpId = user.getCorpId();
        String title =request.getParameter("title").trim();
        if(!ValidateUtils.validateChar(title, "%+") ){
        	return buildResult(false,OperationResult.buildFailureResult("+、%是非法参数，禁止输入!"),null);
        }
        String type = request.getParameter("type");
        String page = request.getParameter("page");
    	String pageSize = request.getParameter("pageSize");
        List<Map> list = forumPostService.getCheckListDing(page, pageSize, user.getJwtToken(), title,type,user);
        Map content = new HashMap();
        content.put("data", list);
        content.put("currentPage", Integer.valueOf(page));
        return buildResult(true, content, null);
    }
	    
	    
    /**
     * 
     * @param request
     * @return
     */
    @ApiOperation(value="获取待审核的数量", notes="获取待审核列表数量")
    @ApiImplicitParams({
    })
    @RequestMapping(value="/queryUncheckCount", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map queryUncheckCount(HttpServletRequest request){
        WebUser user = WebUtils.getCurrentUser();
        String count = forumPostService.queryUncheckCount( user.getJwtToken(),"dingding");
        return buildResult(true, count, null);
    }

    /**
     * 收藏夹列表
     * @param request
     * @return
     */
    @ApiOperation(value="获取收藏夹列表", notes="获取收藏夹列表")
    @ApiImplicitParams({
    })
    @RequestMapping(value="/favoritePostList", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map favoritePostList(HttpServletRequest request){
        WebUser user = WebUtils.getCurrentUser();
        String corpId = user.getCorpId();
        String title =request.getParameter("title").trim();
        String page = request.getParameter("page");
    	String pageSize = request.getParameter("pageSize");
        List<Map> list = forumPostService.getFavoriteListDing(page, pageSize, user.getJwtToken(), title,user);
        Map content = new HashMap();
        content.put("data", list);
        content.put("currentPage", Integer.valueOf(page));
        return buildResult(true, content, null);
    }
	    
	    
    /**
     * 编辑、保存帖子信息
     * @param entity
     * @param request
     * @param model
     * @return
     */
    @ApiOperation(value="编辑、保存帖子信息", notes="编辑、保存帖子信息")
    @ApiImplicitParams({
    })
    @RequestMapping(value="/editPost", method= RequestMethod.POST, produces={"application/json; charset=UTF-8"})
    public Map editSave(@RequestParam("entity") String entity, HttpServletRequest request, Model model){
    	ForumPost c = JSONObject.parseObject(entity, ForumPost.class);
    	String  publistType = request.getParameter("publistType");
    	c.setPublistType(Integer.parseInt(publistType));
        if(StringUtils.isNotBlank(request.getParameter("createdDate"))) {
            c.setCreatedDate(DateUtils.parseTime(request.getParameter("createdDate")));
        }
        if(!ValidateUtils.validateChar(c.getTitle(), "%+")){
        	return buildOperationResult(OperationResult.buildFailureResult("+、%是非法参数，禁止输入"));
		  }
        if(ValidateUtils.validateId(c.getAuthor()) == false){
        	return buildOperationResult(OperationResult.buildFailureResult("非法参数!"));
		  }
        if(!ValidateUtils.validateChar(c.getAttId(), "%+")){
        	return buildOperationResult(OperationResult.buildFailureResult("非法参数!"));
  		  }
        if(!ValidateUtils.validateChar(c.getCheckStatus(), "%+")){
        	return buildOperationResult(OperationResult.buildFailureResult("非法参数!"));
 		  }
        String logCode = "";
        String pagetype = StringUtils.null2String(request.getParameter("pagetypes"));
        String postId = StringUtils.null2String(request.getParameter("postId"));
        String id = StringUtils.null2String(request.getParameter("ids"));
        if(StringUtils.isNotBlank(id)) {
        	if(!StringUtils.equals(c.getCheckStatus(), ForumPost.CheckStatusEnum.CHECK_STATUS_CG.getValue()) && pagetype.contains("draft")) {
            	logCode = "forum:draft:01"; 
            }
        	if(StringUtils.equals(pagetype, "board")) {
        		logCode = "forum:navigation:02"; 
        	}
        	if(StringUtils.equals(pagetype, "mypost")) {
        		logCode = "forum:mypost:02";
        	}
        	if(StringUtils.equals(pagetype, "myreply")) {
        		logCode = "forum:mypost:02";
        	}
		}
        else {
			if(StringUtils.equals(pagetype, "draft")) {
        		logCode = "forum:draft:01"; 
        	}
			if(StringUtils.equals(pagetype, "board")) {
        		logCode = "forum:navigation:01"; 
        	}
        	if(StringUtils.equals(pagetype, "mypost")) {
        		logCode = "forum:mypost:01";
        	}
        	if(StringUtils.equals(pagetype, "myreply")) {
        		logCode = "forum:mypost:01";
        	}
        	if(StringUtils.isBlank(pagetype)) {
        		if(!StringUtils.equals(c.getCheckStatus(), ForumPost.CheckStatusEnum.CHECK_STATUS_CG.getValue())) {
        			logCode = "forum:navigation:01";
        		}
        	}
		}
        OperationResult result = forumPostService.editSave(c, true,request,logCode);
        return buildOperationResult(result);
    }


    /**
     *
     * @Title: replyPost
     * @Description:
     *     回复帖子
     * @param entity
     * @param request
     * @param model
     * @return
     * @return: OperationResult
     *
     * @date 2017年11月27日 下午5:12:48
     *
     */
    @MenuData("回复帖子")
    @ApiOperation(value="回复帖子", notes="回复帖子")
    @ApiImplicitParams({
    })
    @RequestMapping(value="/replyPost", method= RequestMethod.POST, produces={"application/json; charset=UTF-8"})
    public Map replyPost(@RequestParam("entity") String entity, HttpServletRequest request, Model model){
        ForumPost c = JSONObject.parseObject(entity, ForumPost.class);
        if(ValidateUtils.validateId(c.getAuthor()) == false){
        	return buildOperationResult(OperationResult.buildFailureResult("非法参数!"));
		}
        if(!ValidateUtils.validateChar(c.getContent(), "%+") ){
    		return buildOperationResult(OperationResult.buildFailureResult("+、%是非法参数，禁止输入"));
    	}
        String level = request.getParameter("level");
        String receiverId = request.getParameter("receiverId");
        //默认评论为无需审核
		c.setCheckStatus("4");
		//设置未读
		c.setIsRead(1);
        OperationResult result = forumPostService.replyPost(c,request,level,receiverId);
        return buildOperationResult(result);
    }



    /**
     * 查看帖子(帖子信息 + 回帖信息);
     * @param request
     * @return
     */
    @ApiOperation(value="查看帖子(帖子信息 + 回帖信息);", notes="查看帖子(帖子信息 + 回帖信息);")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "帖子Id", required = true, paramType = "path", dataType = "String"),
            @ApiImplicitParam(name = "checkStatus", value = "帖子的审查信息(列表页中的checkstatus值,1-未审核,2-已审核)", required = true, paramType = "path", dataType = "String")
    })
    @RequestMapping(value="/viewPost", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map viewPost(@RequestParam("id") String id, HttpServletRequest request){
        try {
            WebUser user = WebUtils.getCurrentUser();
            ForumPost f  = forumPostService.findOne(id);
            String statu = StringUtils.null2String(request.getParameter("checkStatus"));
            int status = org.ezplatform.util.StringUtils.toInteger(statu);
            if(StringUtils.equals(f.getCheckStatus(), ForumPost.CheckStatusEnum.CHECK_STATUS_SHBTG.getValue())) {
        		ForumPostSendUtils.takeMsgDone(f, user.getCorpId(), user.getJwtToken(), user.getUserId());
            }
            String currentPage = request.getParameter("page");
            String onlyId = request.getParameter("onlyId");
            Pageable pageable = PropertyFilter.buildPageableFromHttpRequest(request);
            List<PropertyFilter> filter = PropertyFilter.buildFiltersFromHttpRequest(ForumPost.class, request);
    		String basicUrl = GlobalConstant.getFlexServerPath(null);
    		Map m = forumPostService.viewPost(pageable, filter, f, user.getJwtToken(), currentPage, status, "dingding",onlyId,basicUrl);
            //Map m = forumPostService.viewPost(pageable, filter, id, user.getJwtToken(), currentPage, status, "dingding",onlyId,basicUrl);
            String title = "";
            if(m!=null && !m.isEmpty()) {
            	boolean isCollection = forumPostService.isCollectionPost(id,WebUtils.getCurrentUser().getUserId());
                m.put("isCollection", isCollection);
                m.put("chexkDelete", "0");
                if(f.getIsDelete() == 1) {
                	m.put("chexkDelete", "1");
                }
                Map mm = (Map)m.get("post");
                title =StringUtils.null2String(mm.get("title"));
            }
            String pagetype = StringUtils.null2String(request.getParameter("pagetype"));
           
            if(StringUtils.null2String(request.getParameter("pagetype")).equals("board")) {
            	logService.saveModuleLog("forum:navigation:03", title, "");
            }
            if(StringUtils.null2String(request.getParameter("pagetype")).equals("myreply")) {
            	logService.saveModuleLog("forum:myreply:03", title, "");
            }
            if(StringUtils.null2String(request.getParameter("pagetype")).equals("mypost")) {
            	logService.saveModuleLog("forum:mypost:03", title, "");
            }
            return buildResult(true, m, "查看帖子信息成功");
        } catch (Exception e){
            LOG.error("查看帖子信息失败", e);
            return buildResult(false, new HashMap(), "查看帖子信息成功");
        }
    }

    /**
     * 获取主题帖/回帖信息
     * @param id
     * @return
     */
    @SuppressWarnings("unchecked")
	@ApiOperation(value="获取主题帖/回帖信息", notes="获取主题帖/回帖信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "帖子Id", required = true, paramType = "path", dataType = "String"),
            @ApiImplicitParam(name = "checkStatus", value = "帖子的审查信息(列表页中的checkstatus值,1-未审核,2-已审核)", required = true, paramType = "path", dataType = "String")
    })
    @RequestMapping(value="/info", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map info(@RequestParam("id") String id, HttpServletRequest request) {
		//try {
			WebUser user = WebUtils.getCurrentUser();
			int type = StringUtils.toInteger(request.getParameter("checkStatus"));
			Map<String,Object> post = forumPostService.findOnePost(id, type, user.getJwtToken(), "dingding",user.getCorpId(),user);
			// 钉钉端需要去掉PC端的样式
			if(MapUtils.isNotEmpty(post)) {
				//根据boardId去查询封装一个   board: { value: 6, text: '版块' }形式
				String  pst =post.get("publistType").toString(); 
				Map<String,Object>  p = new HashMap();
				if(StringUtils.isNotEmpty(pst)) {
					if("1".equals(pst)) {
						p.put("text","主题");
						p.put("value", "1");
					}else {
						p.put("text","公告");
						p.put("value", "2");
					}	
				}
				String boardId=(String)post.get("boardId");
				Map<String,Object>  m=forumBoardService.getForumBoard(boardId);
				post.put("board", m);
				post.put("publishType", p);
				getTextFromHtml(post);
			}
			return buildResult(true, post, "获取主题帖/回帖信息成功");
	/*	} catch (Exception e){
            LOG.error("获取主题帖/回帖信息失败", e);
            return buildResult(false, new HashMap(), "获取主题帖/回帖信息失败");
        }*/
    }
    
	public Map getTextFromHtml(Map<String,Object> post) {
		String content=(String)post.get("content");
		if(StringUtils.isNotEmpty(content)) {
			content = delHTMLTag(content);  
			//content = content.replaceAll("&nbsp;", " ");  
		}
		post.put("content", content);
		return post;
	}
	    
	 /** 
     * @param htmlStr 
     * @return 
     *  删除Html标签 
     */  
    public static String delHTMLTag(String htmlStr) {  
    	// 定义script的正则表达式{或<script[^>]*?>[\\s\\S]*?<\\/script>
		String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>";
		// 定义style的正则表达式{或<style[^>]*?>[\\s\\S]*?<\\/style>
		String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>";
		// 定义HTML标签的正则表达式
		String regEx_html = "<[^>]+>";
		// 定义一些特殊字符的正则表达式 如：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		String regEx_special = "\\&[a-zA-Z]{1,10};";
		String regEx_space = "\\s*|\t|\r|\n";//定义空格回车换行符 
        Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);  
        Matcher m_script = p_script.matcher(htmlStr);  
        htmlStr = m_script.replaceAll(""); // 过滤script标签  
        Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);  
        Matcher m_style = p_style.matcher(htmlStr);  
        htmlStr = m_style.replaceAll(""); // 过滤style标签  
  
        Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);  
        Matcher m_html = p_html.matcher(htmlStr);  
        htmlStr = m_html.replaceAll(""); // 过滤html标签  
  
       // Pattern p_space = Pattern.compile(regEx_space, Pattern.CASE_INSENSITIVE);  
       // Matcher m_space = p_space.matcher(htmlStr);  
       // htmlStr = m_space.replaceAll(""); // 过滤空格回车标签  
        return htmlStr; // 返回文本字符串  
    }  
    
	    

    /**
     * 删除（批量）我的帖子
     */
    @ApiOperation(value="获取主题帖/回帖信息", notes="获取主题帖/回帖信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "帖子Id", required = true, paramType = "path", dataType = "String")
    })
    @RequestMapping(value="/deleteMyPost", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map deleteMyPost(@RequestParam("ids") String... ids){
        try {
            OperationResult result;
            Map r = forumPostService.checkMyDelete(ids);
            if ((boolean) r.get("flag"))
                result = forumPostService.deleteMyPost(ids, r);
            else
                result = new OperationResult(OperationResult.OPERATION_RESULT_TYPE.failure, "帖子所属的版块需要审核无法删除帖子");
            return buildOperationResult(result);
        } catch (Exception e){
            LOG.error("删除我的帖子失败", e);
            return buildOperationResult( new OperationResult(OperationResult.OPERATION_RESULT_TYPE.failure, "删除我的帖子失败"));
        }
    }

    /**
     *
     * @Title: topPost
     * @Description:
     *     帖子置顶
     * @param id
     * @return
     * @return: OperationResult
     *
     */
    @MenuData("帖子置顶")
    @ApiOperation(value="帖子置顶", notes="帖子置顶")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "帖子Id", required = true, paramType = "path", dataType = "String")
    })
    @RequestMapping(value="/topPost", method= RequestMethod.POST, produces={"application/json; charset=UTF-8"})
    public Map topPost(@RequestParam("id") String id){
        return buildOperationResult(forumPostService.topPost(id));
    }
	    
    /**
    *
    * @Title: topPost
    * @Description:
    * 设置精华帖子
    * @param id
    * @return
    * @return: OperationResult
    *
    */
   @MenuData("设置精华帖子")
   @ApiOperation(value="设置精华帖子", notes="设置精华帖子")
   @ApiImplicitParams({
           @ApiImplicitParam(name = "id", value = "帖子Id", required = true, paramType = "path", dataType = "String")
   })
   @RequestMapping(value="/essencePost", method= RequestMethod.POST, produces={"application/json; charset=UTF-8"})
   public Map essencePost(HttpServletRequest request){
	   
	   String id = request.getParameter("id");
       return buildOperationResult(forumPostService.essencePost(id));
   }


    /**
     *
     * @Title: labelPost
     * @Description:
     *     帖子标签修改
     * @param labelId
     * @param postIds
     * @return
     * @return: OperationResult
     *
     * @date 2017年11月24日 下午7:54:14
     *
     */
    @MenuData("帖子增加标签")
    @ApiOperation(value="帖子增加标签", notes="帖子增加标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "labelId", value = "标签Id", required = true, paramType = "path", dataType = "String"),
            @ApiImplicitParam(name = "postIds", value = "帖子ids", required = true, paramType = "path", dataType = "String"),
            @ApiImplicitParam(name = "isFlush", value = "是否刷新, 当值=1时:若不存在标签则添加,存在删除; !=1时:不存在标签添加,存在标签不改变(不会多次添加);", required = true, paramType = "path", dataType = "String")
    })
    @RequestMapping(value="/labelPost", method= RequestMethod.POST, produces={"application/json; charset=UTF-8"})
    public Map labelPost(HttpServletRequest request, @RequestParam("labelId") String labelId, @RequestParam("postIds") String... postIds){
        String isFlush = request.getParameter("isFlush");
        return buildOperationResult(forumPostLabelService.labelPost(labelId, isFlush, postIds));
    }

    /**
     *
     * @Title: deletePost
     * @Description:
     *     删除帖子、回帖
     * @param ids
     * @return: void
     * @throws ParseException 
     *
     * @date 2017年11月27日 下午6:54:59
     *
     */
    @ApiOperation(value="删除帖子、回帖", notes="删除帖子、回帖")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "帖子ids", required = true, paramType = "path", dataType = "String")
    })
    @RequestMapping(value="/delete", method= RequestMethod.POST, produces={"application/json; charset=UTF-8"})
    public Map delete(HttpServletRequest request ,@RequestParam("ids") String... ids ) throws ParseException{
        OperationResult result ;
        String logCode = "";
        String pagetype = StringUtils.null2String(request.getParameter("pagetype"));
        if(StringUtils.null2String(request.getParameter("pagetype")).equals("board")) {
        	logCode = "forum:navigation:04";
        }
        if(StringUtils.null2String(request.getParameter("pagetype")).equals("mypost")) {
        	logCode = "forum:mypost:04";
        }
        result = forumPostService.deletePost(ids,logCode);
        return buildOperationResult(result);
    }

	    /**
	     *
	     * @Title: checkPost
	     * @Description:
	     *     审核帖子
	     * @param ids
	     * @return
	     * @return: OperationResult
	     *
	     * @date 2017年11月25日 下午4:15:15
	     *
	     */
	    /*@ApiOperation(value="审核帖子", notes="审核帖子")
	    @ApiImplicitParams({
	            @ApiImplicitParam(name = "ids", value = "帖子ids", required = true, paramType = "path", dataType = "String")
	    })
	    @RequestMapping(value="/checkPost", method= RequestMethod.POST, produces={"application/json; charset=UTF-8"})
	    public Map checkPost(@RequestParam("ids") String... ids){
	        OperationResult result = forumPostCheckService.checkPost(ids);
	        return buildOperationResult(result);
	    }*/

    /**
     * 将钉钉的附件信息转换并,保存附件信息表,返回附件id(用 | 分割);
     *
     * @param attachment
     * @return
     */
    private String transformAttchmentDd2Platform(String attachment) {
        List<String> attrs = new ArrayList<>();
        WebUser user = WebUtils.getCurrentUser();
        if (StringUtils.isNotEmpty(attachment)) {
            JSONArray att = JSON.parseArray(attachment);
            for (int i = 0; i < att.size(); i++) {
                JSONObject o = att.getJSONObject(i);
                JSONObject d = new JSONObject();
                d.put("fileName", o.getString("fileName"));
                d.put("contentType", StringUtils.SPACE);
                d.put("fileSize", o.getString("fileSize"));
                d.put("fileExt", StringUtils.SPACE);
                d.put("relativePath", StringUtils.SPACE);
                d.put("clientIp", StringUtils.SPACE);
                d.put("dingSpaceId", o.getString("spaceId"));
                d.put("dingFileId", o.getString("fileId"));
                String s = JSON.toJSONString(d);
                Map attMap=attachmentUtilsService.createAttachmentInfo(s, user.getJwtToken());
                attrs.add(attMap.get("id")+"");
            }
        }
        String attids = StringUtils.join(attrs, "|");
        LOG.debug("att id is: " + attids);
        return attids;
    }

    /**
     * 根据附件id获取到附件的具体信息,并封装成钉钉app适应的格式
     * @param attid 附件id用|分割
     * @return
     */
    private Object transformAttachmentPlanform2Dd(String attid){
        Object data = new JSONArray();
        WebUser user = WebUtils.getCurrentUser();
        if(StringUtils.isNotEmpty(attid)){
            Map param2 = new HashMap();
            param2.put("fids", attid);
            try {
                String scopeMap1 = restClient.get("/cmp/attachment/getAttachmentInfos", user.getJwtToken(), param2);
                Map<String,Object> map1 = JsonUtils.readValue(scopeMap1);
                if(StringUtils.equals("success", StringUtils.null2String(map1.get("type")))){
                    data = map1.get("data");
                }
            }catch (Exception e){
                LOG.error("钉钉APP获取表单详情中的附件获取失败");
                LOG.error(e.getMessage());
            }
        }
        return data;
    }

    /**
     * 将钉钉端用户选择得到的scope格式数据中的用户id转换为平台用户id,
     * <p>
     * {"scopeType":"user","scopeValue":"钉钉用户id","scopeName":"论坛1"}
     *
     * @param userStr
     * @return
     */
    private String transformUserScopeDd2Platform(String userStr) {
        if(StringUtils.isNotBlank(userStr)) {
            WebUser user = WebUtils.getCurrentUser();
            //  对审批人的id进行处理,接受到的id为钉钉用户id,需要转换成平台用户id
            JSONArray ddUserArray = JSONArray.parseArray(userStr);
            JSONArray platformArray = new JSONArray();
            for (int i = 0; i < ddUserArray.size(); i++) {
                JSONObject object = ddUserArray.getJSONObject(i);
                String ddUserId = object.getString("scopeValue");
                LOG.debug("auditorUserId ding: " + ddUserId);
                List<String> l = userApiService.getUserIdBySysOrThird(ddUserId,"0","", user.getCorpId(), user.getJwtToken());
                if (!CollectionUtils.isEmpty(l)) {
                    String s_change = l.get(0);
                    LOG.debug("auditorUserId flex: " + s_change);
                    object.put("scopeValue", s_change);
                }
                platformArray.add(object);
            }

            return platformArray.size() == 0 ? "" : JSON.toJSONString(platformArray);
        } else {
            return userStr;
        }
    }

    /**
     * 根据scope所需的信息获取scope中的用户,
     * 并将用户信息封装成钉钉salt-ui组件可接受格式
     *
     * @param fieldDataValue
     * @param tableName
     * @param fieldDataTable
     * @param fieldData
     * @return
     */
    private List<Map> transformUserScopePlatform2Dd(String fieldDataValue, String tableName, String fieldDataTable, String fieldData){
        WebUser user = WebUtils.getCurrentUser();
        List<Map> re = new ArrayList();
        String scopeTypeStr = popUserScopeUtilService.getScopeTypeValue(tableName, fieldDataTable, fieldData, StringUtils.null2String(fieldDataValue));
        // userSCOPE8a53b7845fe14546015fe19cba140016,userSCOPE8a53b7845fe14546015fe19c62020014
        String scopeNameStr = userApiService.getScopeName(scopeTypeStr, user.getCorpId(), user.getJwtToken());
        String[] scopeTypeArray = scopeTypeStr.split(",");
        String[] scopeNameArray = scopeNameStr.split(",");
        if(scopeTypeArray != null && scopeTypeArray.length>0) {
            for (int i = 0; i < scopeTypeArray.length; i++) {
                String[] info = scopeTypeArray[i].split("SCOPE");
                if (info.length > 1){
                    String id  = info[1];
                    Map m = new HashMap();
                    List<String> l = userApiService.getUserIdBySysOrThird(id,"1","DD", user.getCorpId(), user.getJwtToken());
                    if(!CollectionUtils.isEmpty(l)) {
                        m.put("key", l.get(0));
                        m.put("label", scopeNameArray[i]);
                        re.add(m);
                    }
                }
            }
        }
        return re;
    }
	    
	    
    /**
     * 标签管理
     * @param entity
     * @param request
     * @param model
     * @return
     */
    @ApiOperation(value="编辑、保存帖子信息", notes="编辑、保存帖子信息")
    @ApiImplicitParams({
    })
    @RequestMapping(value="/editPostLabel", method= RequestMethod.POST, produces={"application/json; charset=UTF-8"})
    public Map editPostLabel( HttpServletRequest request, Model model){
    	String postId=request.getParameter("postId");
    	String newLabelId=request.getParameter("newIdArray");//修改后的
    	String[] newLabelIdArray = new String[]{};
    	List<String> labelIdList=new ArrayList<String>();
    	String isToggle="0";
    	//如果原有的有值，而修改后的没有值，说明是取消了所有的标签
    	if(StringUtils.isNotEmpty(newLabelId)){
    		newLabelId=newLabelId.substring(0, newLabelId.lastIndexOf("|"));
    		newLabelIdArray=newLabelId.split("\\|");
    	}
    	/*if(newLabelIdArray.length==0 && labelIdArray.length>0) {
    		//	
    		isToggle="1";//删除
    		newLabelIdArray=labelIdArray;
    	}*/
    	if(null != newLabelIdArray && newLabelIdArray.length > 0 ) {
    		labelIdList = Arrays.asList(newLabelIdArray);
    	}
    	OperationResult result=forumPostLabelService.editPostLabel(postId,labelIdList);
    	return buildOperationResult(result);
    }
    
    @ApiOperation(value="移动版块", notes="移动版块")
    @ApiImplicitParams({})
    @RequestMapping(value="/editPostBoard", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map editPostBoard(HttpServletRequest request) {
    	String postId = request.getParameter("postId");
    	String[] ids = {postId};
    	String oldBoardID = request.getParameter("oldBoardId");
    	String newBoardId = request.getParameter("boardId");
    	if(StringUtils.isEmpty(newBoardId)) {
    		Map resources = new HashMap();
    		//国际化资源
    		resources.put("i18NCode", "oa.forum.movesuc");
    		OperationResult buildSuccessResult = OperationResult.buildSuccessResult("移动成功",resources);
    		return buildOperationResult(buildSuccessResult);
    	}
    	OperationResult result = forumPostService.changePostStatus(ids, newBoardId,request);
    	return buildOperationResult(result);
    }
	    
    @ApiOperation(value="获取帖子回复数量", notes="获取帖子回复数量")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "id", value = "帖子Id", required = true, paramType = "path", dataType = "String")
    })
    @RequestMapping(value="/queryReplyCount", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map getReplyCount(HttpServletRequest request, @RequestParam("id") String postId) {
    	Map map = forumPostService.getReplyCount(postId);
    	String count = "0";
    	if(map != null) {
    		count = StringUtils.null2String(map.get("replyCount"));
    	}
    	return buildResult(true, count, null);
    }
	    
    /**
     * 查看版块信息;
     * @param request
     * @return
     */
    @ApiOperation(value="查看版块信息;", notes="查看版块信息;")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "帖子Id", required = true, paramType = "path", dataType = "String"),
    })
    @RequestMapping(value="/getBoardInfo", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map getBoardInfo(@RequestParam("id") String id, HttpServletRequest request){
    	ForumBoard b = forumBoardService.findOne(id);

        Map m = null;
        try {
            m = BeanUtils.describe(b);
            String moderatorStr = popUserScopeUtilService.getScopeTypeValue("oa_forum_moderator_scope", "oa_forum_board", "id", StringUtils.null2String(id));
            String userStr = popUserScopeUtilService.getScopeTypeValue("oa_forum_board_user_scope", "oa_forum_board", "id", StringUtils.null2String(id));
            m.put("moderatorStr", moderatorStr);
            m.put("userStr", userStr);
            int postCount = forumBoardService.getPostNum(id,"1",WebUtils.getCurrentUser().getCorpId());
            m.put("postCount", String.valueOf(postCount));
            int replyCount = forumBoardService.getPostNum(id,"2",WebUtils.getCurrentUser().getCorpId());
            m.put("replyCount", String.valueOf(replyCount));
            return buildResult(true, m, "查看帖子信息成功");
        } catch (Exception e){
            LOG.error("查看帖子信息失败", e);
            return buildResult(false, new HashMap(), "查看帖子信息成功");
        }
    }
	    
    /**
	 * 收藏/取消收藏帖子
	 * @param request
     * @param id
     * @return
	 */
    @ApiOperation(value="收藏/取消收藏帖子;", notes="收藏/取消收藏帖子;")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "帖子Id", required = true, paramType = "path", dataType = "String"),
    })
    @RequestMapping(value="/collectionPost", method= RequestMethod.POST, produces={"application/json; charset=UTF-8"})
	public Map collectionPost(HttpServletRequest request, @RequestParam("id") String id) {
		OperationResult result;
        WebUser user = WebUtils.getCurrentUser();
        result = forumPostService.favoritePost(id, user.getUserId(), user.getCnName(),user.getCorpId(),user);
		return buildOperationResult(result);
	}
	    
	    
    /**
     * 获取待审核列表
     * @param request
     * @return
     */
    @ApiOperation(value="获取待审核列表", notes="获取待审核列表")
    @ApiImplicitParams({
    })
    @RequestMapping(value="/queryPostPageComment", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map queryPostPageComment(HttpServletRequest request){
        WebUser user = WebUtils.getCurrentUser();
        String corpId = user.getCorpId();
        String id = request.getParameter("id");
        String page = request.getParameter("page");
    	String pageSize = request.getParameter("pageSize");
        List<Map> list = forumPostService.getCommentsDing(page, pageSize, user.getJwtToken(),user,id);
        Map content = new HashMap();
        content.put("data", list);
        content.put("currentPage", Integer.valueOf(page));
        return buildResult(true, content, null);
    }
	    
    /**
     * 查看帖子(回帖信息);
     * @param request
     * @return
     */
    @ApiOperation(value="查看帖子(回帖信息);", notes="查看帖子(回帖信息);")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "回帖Id", required = true, paramType = "path", dataType = "String"),
    })
    @RequestMapping(value="/viewReplyPost", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map viewReplyPost(@RequestParam("id") String id, HttpServletRequest request){
        try {
            WebUser user = WebUtils.getCurrentUser();
            Map m = forumPostService.viewReplyPost(id,"dingding",user);
            return buildResult(true, m, "查看帖子信息成功");
        } catch (Exception e){
            LOG.error("查看帖子信息失败", e);
            return buildResult(false, new HashMap(), "查看帖子信息成功");
        }
    }
	    
    /**
     * 
     * @param request
     * @return
     */
    @ApiOperation(value="获取论坛动态(回复我的,评论我的是否有未读信息)", notes="获取论坛动态(回复我的,评论我的是否有未读信息)")
    @RequestMapping(value="/getIfReadAll", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map getIfReadAll(HttpServletRequest request){
        WebUser user = WebUtils.getCurrentUser();
        try {
        	//获取回复我的和评论我的数量
    		List<Map> allPost1 = forumPostService.findIfRead(user.getUserId(),"2");
    		List<Map> allPost2 = forumPostService.findIfRead(user.getUserId(),"3");
    		//评论我的
    		boolean contactMine = allPost1.size() > 0 ? true : false ;
    		//回复我的
    		boolean commentMine = allPost2.size() > 0 ? true : false ;
    		Map map = new HashMap();
    		map.put("contactMine", contactMine);
    		map.put("commentMine", commentMine);
    		return buildResult(true, map, "获取论坛动态(回复我的,评论我的是否有未读信息)");
        }catch(Exception e) {
        	LOG.error("查看帖子信息失败", e);
            return buildResult(false, new HashMap(), "获取论坛动态(回复我的,评论我的是否有未读信息)失败");
        }
    }
	    
    /**
     * 
     * @param request
     * @return
     */
    @ApiOperation(value="获取我的论坛页面信息", notes="获取我的论坛页面信息")
    @RequestMapping(value="/initUserInfo", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map initUserInfo(HttpServletRequest request){
        WebUser user = WebUtils.getCurrentUser();
        try {
        	 Map initInfo = forumPostService.initUserInfo(user);
        	// 判断当前用户是否是系统管理员或者应用管理员
             if(SecurityUtils.isSuperAdmin(user)||user.getRoleCodes().contains(ForumPost.CheckStatusEnum.YYGLYQX.getValue()) || user.getRoleCodes().contains("appUserRole")){
            	 initInfo.put("isAdmin", true);
             } else {
            	 initInfo.put("isAdmin", false);
             }
             return buildResult(true, initInfo, "获取我的论坛页面信息成功");
        }catch(Exception e) {
        	LOG.error("获取我的论坛页面信息失败", e);
            return buildResult(false, new HashMap(), "获取我的论坛页面信息失败");
        }
       
    }
	    
    /**
     * 获取论坛提醒列表数据;
     * @param request
     * @return
     */
    @ApiOperation(value="获取论坛提醒列表数据", notes="获取论坛提醒列表数据")
    @RequestMapping(value="/queryRemindList", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map queryRemindList(HttpServletRequest request){
        try {
            WebUser user = WebUtils.getCurrentUser();
            String page = request.getParameter("page");
        	String pageSize = request.getParameter("pageSize");
        	String remindPageType = request.getParameter("remindPageType");
        	List<Map> list= forumPostService.getRemindList(page,pageSize, user,remindPageType);
        	Map content = new HashMap();
            content.put("data", list);
            content.put("currentPage", Integer.valueOf(page));
            return buildResult(true, content, "获取论坛提醒列表信息成功");
        } catch (Exception e){
            LOG.error("查看帖子信息失败", e);
            return buildResult(false, new HashMap(), "获取论坛提醒列表信息失败");
        }
    }
	    
    /**
     * 获取我可以审核的帖子;
     * @param request
     * @return
     */
    @ApiOperation(value="获取我可以审核的帖子", notes="获取我可以审核的帖子")
    @RequestMapping(value="/checkMyPost", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map getCheckMyPost(HttpServletRequest request) {
    	try {
    		String corpId = WebUtils.getCurrentUser().getCorpId();
    		WebUser user = WebUtils.getCurrentUser();
     		Pageable pageable = PropertyFilter.buildPageableFromHttpRequest(request);
     		String title1 = request.getParameter("title").trim();
     		if(title1.isEmpty()) {
     			title1 = "";
     		}
     		String page = request.getParameter("page");
         	String pageSize = request.getParameter("pageSize");
     		List<PropertyFilter> filter = PropertyFilter.buildFiltersFromHttpRequest(ForumPost.class, request);
        	List<Map> list = forumPostService.checkListDing(page, pageSize, filter, user.getJwtToken(),"dingding",title1,corpId);
        	Map content = new HashMap();
            content.put("data", list);
            content.put("currentPage", Integer.valueOf(page));
        	return buildResult(true, content, "获取我可以审核的帖子成功");
    	} catch (Exception e){
    		LOG.error("查看帖子信息失败", e);
            return buildResult(false, new HashMap(), "获取我可以审核的帖子失败");
    	}
    	
    }
	    
    /**
     * 审核帖子(审核不通过)
     * @param request
     * @return
     */
    @ApiOperation(value="审核帖子(审核不通过)", notes="审核帖子(审核不通过)")
    @RequestMapping(value="/returnInfo", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map returnInfo(HttpServletRequest request) {
		String id = request.getParameter("id");
		String[] ids = {id};
		String rejection = request.getParameter("rejction");
		ForumPost post = forumPostService.findOne(id);
		logService.saveModuleLog("forum:check:02",post.getTitle(), "");
		OperationResult result =  forumPostService.checkPostInfo(ids,ForumPost.CheckStatusEnum.CHECK_STATUS_SHBTG.getValue(),rejection,request);
    	return buildResult(true, new HashMap(), "提交成功");
    }
	    
    @ApiOperation(value="审核帖子(审核通过)", notes="审核帖子(审核通过)")
    @RequestMapping(value="/returnPost", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map checkPostInfo(HttpServletRequest request) {
    	String id = request.getParameter("id");
    	String[] ids = {id};
		ForumPost post = forumPostService.findOne(id);
		logService.saveModuleLog("forum:check:01",post.getTitle(), "");
    	OperationResult result =  forumPostService.checkPostInfo(ids,"1","",request);
    	return buildResult(true, result, "提交成功");
    }
    
    @SuppressWarnings({ "unchecked", "rawtypes", "rawtypes" })
	@ApiOperation(value="当前用户是否有昵称", notes="当前用户是否有昵称")
    @RequestMapping(value="/ifPetname", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map ifPetname(HttpServletRequest request){
    	//判断当前用户是否有昵称
    	//取用户个性签名、昵称
    	WebUser webUser = WebUtils.getCurrentUser();
    	String userId = webUser.getUserId();
    	Map<String, String> textParams = Maps.newHashMap();
    	textParams.put("userId", userId);
		textParams.put("corpId", webUser.getCorpId());
		String jsonStr = this.restClient.get("/portal/setting/userinfo/getUserExt", webUser.getJwtToken(), textParams);
		Map<String, Object> result = JsonUtils.readValue(jsonStr);
		result = JsonUtils.readValue(jsonStr);
		String petName ="";
		if("0".equals(StringUtils.null2String(result.get("code")))){
			if(result.get("data")!=null) {
				Map<String, Object> userExtMap = Maps.newHashMap();
				userExtMap = (Map<String, Object>) result.get("data");
				petName = StringUtils.null2String(userExtMap.get("petName"));
			}
		}
		Map<String,String> data = new HashMap();
		data.put("petName", petName);
        List<Map> list = new ArrayList();
        list.add(data);
        return buildResult(true, data, "获取用户昵称成功");
    }
    
    @SuppressWarnings({ "unchecked", "rawtypes", "rawtypes" })
	@ApiOperation(value="获取论坛积分数据", notes="获取论坛积分数据")
    @RequestMapping(value="/getIntegralViewInfo", method= RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public Map getIntegralViewInfo(HttpServletRequest request){
    	WebUser user = WebUtils.getCurrentUser();
    	ForumIntegral forumIntegral = forumIntegralService.getIntegralViewInfo(user.getUserId());
    	Map<String,String> data = new HashMap();
    	if(forumIntegral!=null) {
    		data.put("integralScore", forumIntegral.getTotalScore()+"");
    	}else {
    		data.put("integralScore", "0");
    	}
        List<Map> list = new ArrayList();
        list.add(data);
        return buildResult(true, data, "获取论坛积分数据成功");
    }

}
